precision highp float;

uniform sampler2D u_tex;
uniform vec2 u_screen_size;
uniform vec2 u_center;
uniform float u_radian;
uniform float u_step;

varying vec2 v_uv;


void main () {
	vec2 rec_screen_size = 1.0 / u_screen_size;
	vec2 center = u_center;
	vec2 pos = v_uv * u_screen_size;
	vec2 vec = pos - center;
	float radius = length(vec);
	float radian0 = atan(vec.y, vec.x);
	float samples = ceil(u_radian * 0.5 * radius / u_step);
	float dRadian = u_radian * 0.5 / (samples + 0.1);
	float aRadian = dRadian;

	vec4 sum = texture2D(u_tex, v_uv);
	for (int i = 0; i < int(samples); ++i) {
		vec2 v1 = vec2(cos(radian0 + aRadian), sin(radian0 + aRadian)) * radius;
		vec2 v2 = vec2(cos(radian0 - aRadian), sin(radian0 - aRadian)) * radius;
		vec2 uv1 = (center + v1) * rec_screen_size;
		vec2 uv2 = (center + v2) * rec_screen_size;
		sum += texture2D(u_tex, uv1);
		sum += texture2D(u_tex, uv2);
		aRadian += dRadian;
	}
	gl_FragColor = sum / (1.0 + samples * 2.0);
}